using System.Diagnostics;

namespace CoverageRunner
{
    public class UnitTestRunner
    {
        private readonly string _executable;
        private readonly string _arguments;
        private int _exitCode;
        
        public UnitTestRunner(string executable, string[] arguments)
        {
            _executable = executable;
            _arguments = string.Join(", ", arguments);
        }

        public int ExitCode
        {
            get { return _exitCode; }
        }

        public string Execute()
        {
            var processRunner = new Process
                                    {
                                        StartInfo =
                                            {
                                                UseShellExecute = false,
                                                RedirectStandardOutput = true,
                                                FileName = _executable,
                                                Arguments = _arguments
                                            }
                                    };
            processRunner.Start();
            processRunner.WaitForExit();
            string output = processRunner.StandardOutput.ReadToEnd();
            _exitCode = processRunner.ExitCode;
            return output;
        }       
    }
}